package com.langfeiyes.pattern.template.demo2;

import java.util.TimerTask;

public  abstract  class LogicStatisTime {
    //模板方法，固定统计时间算法
    public  final void excute(TaskJob taskJob){
        long begin = this.begin();
        taskJob.doJob();
        long end = this.end();
        this.statis(begin, end);
        this.endStatis();
    }
    //开始计时，算法步骤，固定
    private Long begin(){
        long begin = System.currentTimeMillis();
        System.out.println("计时开始T1：" + begin);
        return begin;
    }
    //结算计时，算法步骤，固定
    private Long end(){
        long end = System.currentTimeMillis();
        System.out.println("计时结束T2：" + end);
        return end;
    }
    //算法时间统计，算法步骤，由子类
    protected  abstract void statis(Long begin, Long end);

    //算法步骤，父类默认实现，子类可以选择性拓展
    protected void endStatis() {
        System.out.println("欢迎关注：下岗码农大飞");
    }
}
